/***************************************************************************
 *   Copyright (C) 2009 by Marian Skvarek   *
 *   skvarek.marian@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "CPositionList.h"

namespace easyscore
{
    namespace core
    {

        //Constructors, Initialization & Destructors


        CPositionList::CPositionList()
        {
            initialize();
        }

        CPositionList::CPositionList(const CPositionList & image)
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                mPositions[i] = image.mPositions[i];
        }

        void CPositionList::initialize()
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                mPositions[i] = false;
        }

        void CPositionList::clear()
        {

        }

        CPositionList::~CPositionList()
        {
            clear();
        }

        //Overrides

        //Public methods

        void CPositionList::set(int pos,bool value)
        {
            if(pos >= 0 && pos < FRETBOARD_SIZE)
                mPositions[pos] = value;
        }

        bool CPositionList::isEmpty()
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                if(mPositions[i])
                    return false;
            return true;
        }

        void CPositionList::andIt(const CPositionList &op)
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                mPositions[i] = op.mPositions[i] && mPositions[i];
        }

        void CPositionList::ones()
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                mPositions[i] = true;
        }

        void CPositionList::zeros()
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                mPositions[i] = false;
        }

        int CPositionList::getFirstNonZero()
        {
            for(int i = 0; i < FRETBOARD_SIZE; ++i)
                if(mPositions[i])
                    return i;

            return -1;
        }

        //Protected methods

        //Private methods

    }//namespace utils
}//namespace easyscore
